import {
  Column,
  Entity,
  JoinColumn,
  JoinTable,
  ManyToMany,
  ManyToOne,
  OneToMany,
  OneToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { ClassAttribute } from '../../entities/dbField';
import { Teacher } from '../../teacher/entities/teacher.entity';
import { LessonsSort } from '../../lessons-sort/entities/lessons-sort.entity';
import { Major } from '../../major/entities/major.entity';
import { Exclude } from 'class-transformer';

/***
 * 课程
 */
@Entity()
export class Course {
  @PrimaryGeneratedColumn({ comment: '课程id' })
  id: number;

  @Column({ comment: '课程名称' })
  name: string;

  @Column({ comment: '课程描述' })
  desc: string;

  @Column({ comment: '计划人数', nullable: true })
  planPeopleNumber: number;

  @Column({ comment: '实际人数' })
  realityPeopleNumber: number;

  @Column({ comment: '学分' })
  credit: number;

  @Column({
    comment: '课程属性',
    type: 'enum',
    enum: ClassAttribute,
    default: ClassAttribute.PUBLIC,
  })
  attribute: ClassAttribute;

  @Column({ comment: '老师表id', nullable: true })
  teacher_id: number;
  @ManyToOne(() => Teacher, (teacher) => teacher.course, {
    onDelete: 'SET NULL',
  })
  @JoinColumn({
    name: 'teacher_id',
  })
  teacher: Teacher;

  @Column({ comment: '专业表id' })
  major_id: number;
  @ManyToOne(() => Major, (major) => major.course)
  @JoinColumn({
    name: 'major_id',
  })
  major: Major;

  @OneToMany(() => LessonsSort, (lessonsSort) => lessonsSort.course, {
    onDelete: 'SET NULL',
  })
  lessonsSorts: LessonsSort[];
}
